#include <stdio.h>
#include <math.h>
#include <stdlib.h>

//resolution in bits (12 bits, 11 bits, 10 bits or 9 bits)
float tempTI(unsigned char resolution, unsigned int rawTemperature)
{
	float tempTI;	
	unsigned char shift = (resolution!=12)?(resolution%4):4;
	float comma;

	if (resolution != 12)
		rawTemperature = (rawTemperature >> 4) >> (4-(resolution%4));
	else 
		rawTemperature = (rawTemperature >> 4);
	printf("\n0x%x",rawTemperature);
		
	if (rawTemperature < (unsigned int)0x800)
	{
	tempTI = (float)(rawTemperature >> shift); //low-byte part (number)
	comma = (float)(rawTemperature % (unsigned int)pow(2,shift));
	if (comma != 0)
		tempTI+= 0.0625 * comma; //high-byte part (comma)
	}
	else
	{
		rawTemperature = (pow(2,8+shift) - (rawTemperature));
		tempTI = (float)(rawTemperature >> shift); //low-byte part (number)
		comma = (float)(rawTemperature % (unsigned int)pow(2,shift));
		if (comma != 0)
			tempTI+= 0.0625 * comma; //high-byte part (comma)
		tempTI = 0 - tempTI;
	}
	return tempTI;
}

void main(void)
{
unsigned int rawTemp;
printf("Temperatura =");
scanf("%x",&rawTemp);
printf("Temperatura = %.2f",tempTI(12,rawTemp));

}